home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / enumfont / enumfont.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  5.5 KB  |  157 lines

  1. VERSION 2.00
  2. Begin Form form_enumfont 
  3.    Caption         =   "EnumFonts Demo"
  4.    ClientHeight    =   3000
  5.    ClientLeft      =   870
  6.    ClientTop       =   2730
  7.    ClientWidth     =   6945
  8.    Height          =   3690
  9.    Icon            =   0
  10.    Left            =   810
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   3000
  14.    ScaleWidth      =   6945
  15.    Top             =   2100
  16.    Width           =   7065
  17.    Begin ListBox lst_fonts 
  18.       Height          =   2175
  19.       Left            =   2520
  20.       TabIndex        =   3
  21.       Top             =   600
  22.       Width           =   4095
  23.    End
  24.    Begin ListBox Lst_Faces 
  25.       Height          =   2175
  26.       Left            =   360
  27.       TabIndex        =   1
  28.       Top             =   600
  29.       Width           =   1935
  30.    End
  31.    Begin Label Label2 
  32.       Alignment       =   2  'Center
  33.       Caption         =   "Fonts"
  34.       Height          =   255
  35.       Left            =   2520
  36.       TabIndex        =   2
  37.       Top             =   240
  38.       Width           =   4095
  39.    End
  40.    Begin Label Label1 
  41.       Alignment       =   2  'Center
  42.       Caption         =   "Typefaces"
  43.       Height          =   255
  44.       Left            =   360
  45.       TabIndex        =   0
  46.       Top             =   240
  47.       Width           =   1935
  48.    End
  49.    Begin Menu menu_file 
  50.       Caption         =   "&File"
  51.       Begin Menu menu_file_exit 
  52.          Caption         =   "&Exit"
  53.       End
  54.    End
  55.    Begin Menu menu_help 
  56.       Caption         =   "&Help"
  57.       Begin Menu menu_help_about 
  58.          Caption         =   "&About"
  59.       End
  60.    End
  61. ' Copyright (C) Telelink Systems 1991
  62. ' Phone:  (916) 332-2671
  63. ' Fax:    (916) 332-2529
  64. ' Cserve: 70523,2574
  65. Sub cmd_OK_Click ()
  66.    Unload form_Enumfont
  67. End Sub
  68. Sub Form_Load ()
  69.    '-- Find how many typefaces are there
  70.    nFaceCnt% = VBEnumFonts(Printer.hDC, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, 0)
  71.    '-- Prepare an array for the typefaces
  72.    ReDim lfFace(nFaceCnt% - 1) As LOGFONT
  73.    '-- Fill the array -- one entry for each typeface
  74.    dummy% = VBEnumFonts(Printer.hDC, ByVal 0&, lfFace(0), ByVal 0&, ByVal 0&, nFaceCnt%)
  75.    '-- Add the typeface names to the list box
  76.    For Face% = 0 To nFaceCnt% - 1
  77.       '-- retrieve face name
  78.       st$ = lfFace(Face%).lfFaceName
  79.       '-- trim the fixed string into a variable string
  80.       lst_faces.AddItem Left$(st$, InStr(st$, Chr$(0)) - 1)
  81.    Next Face%
  82.    '-- point to first typeface -- this will trigger a click event
  83.    '   for the lst_faces object
  84.    lst_faces.listindex = 0
  85. End Sub
  86. Sub Form_Resize ()
  87.    lst_faces.SetFocus
  88. End Sub
  89. Sub Lst_Faces_Click ()
  90.    If lst_faces.listindex >= 0 Then
  91.       '-- clear font list
  92.       Do While lst_Fonts.listcount > 0
  93.          lst_Fonts.RemoveItem 0
  94.       Loop
  95.       
  96.       '-- find how many fonts in this typeface
  97.       FaceName$ = lst_faces.list(lst_faces.listindex)
  98.       nFontcnt% = VBEnumFonts(Printer.hDC, FaceName$, ByVal 0&, ByVal 0&, ByVal 0&, 0)
  99.       
  100.       '-- Prepare 3 arrays to receive font information
  101.       ReDim lfFont(nFontcnt% - 1) As LOGFONT
  102.       ReDim tmFont(nFontcnt% - 1) As TEXTMETRIC
  103.       ReDim nTypeFont(nFontcnt% - 1) As Integer
  104.       '-- change mapping mode to pixels, fill arrays, and restore mapping mode
  105.       oldMapMode% = SetMapMode(Printer.hDC, MM_TEXT)
  106.       dummy% = VBEnumFonts(Printer.hDC, FaceName$, lfFont(0), tmFont(0), nTypeFont(0), nFontcnt%)
  107.       dummy% = SetMapMode(Printer.hDC, oldMapMode%)
  108.       
  109.       '-- find pixels per inch for printer
  110.       pixels_per_inch% = GetDeviceCaps(Printer.hDC, LOGPIXELSY)
  111.       '-- reflect the information into the font list
  112.       For font% = 0 To nFontcnt% - 1
  113.          '-- Font size, in points, is twips divided by 20
  114.          st$ = Str$(tmFont(font%).tmHeight * 72 / pixels_per_inch%) + " Pts"
  115.          '-- add italic/bold/etc
  116.          If Asc(tmFont(font%).tmItalic) Then st$ = st$ + " Italic"
  117.          If Asc(tmFont(font%).tmUnderlined) Then st$ = st$ + " Underline"
  118.          If Asc(tmFont(font%).tmStruckout) Then st$ = st$ + " Strikeout"
  119.          If tmFont(font%).tmWeight > 550 Then st$ = st$ + " Bold"
  120.          '-- font pitch
  121.          Select Case (Asc(tmFont(font%).tmPitchAndFamily) And &H1)
  122.            Case 0:   st$ = st$ + " Fixed"
  123.            Case 1: st$ = st$ + " Var"
  124.          End Select
  125.          '-- What kind of font?
  126.          Select Case (Asc(tmFont(font%).tmPitchAndFamily) And &HF0)
  127.            Case FF_DECORATIVE: st$ = st$ + ", Decorative"
  128.            Case FF_DONTCARE: st$ = st$ + ", Dontcare"
  129.            Case FF_MODERN: st$ = st$ + ", Modern"
  130.            Case FF_ROMAN: st$ = st$ + ", Roman"
  131.            Case FF_SCRIPT: st$ = st$ + ", Script"
  132.            Case FF_SWISS: st$ = st$ + ", Swiss"
  133.            Case Else: st$ = st$ + ", FF_Error"
  134.          End Select
  135.          '-- font type
  136.          Select Case nTypeFont(font%) And &H3
  137.             Case 0: st$ = st$ + " GDI Stroke"
  138.             Case 1: st$ = st$ + " GDI Raster"
  139.             Case 2: st$ = st$ + " Device Stroke"
  140.             Case 3: st$ = st$ + " Device Raster"
  141.          End Select
  142.          lst_Fonts.AddItem st$
  143.       Next font%
  144.    End If
  145. End Sub
  146. Sub menu_file_exit_Click ()
  147.   End
  148. End Sub
  149. Sub menu_help_about_Click ()
  150.   msg1$ = "Copyright (C) Telelink Systems 1991"
  151.   msg2$ = "Phone:  (916) 332-2671"
  152.   msg3$ = "Fax:    (916) 332-2529"
  153.   msg4$ = "Cserve:  70523,2574"
  154.   crlf$ = Chr$(10) + Chr$(13)
  155.   MsgBox msg1$ + crlf$ + crlf$ + msg2$ + crlf$ + msg3$ + crlf$ + msg4$
  156. End Sub
  157.